import React, { useState } from 'react';

import { Row, Col, Upload, Card, Button, Space, Table } from 'antd';
const { Dragger } = Upload;

export default (params) => {
  const [img, setImg] = useState(null);

  const getBase64 = (file) => {
    return new Promise((resolve, reject) => {
      const reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = () => resolve(reader.result);
      reader.onerror = (error) => reject(error);
    });
  };

  // 上传参数
  const upload_props = {
    name: 'file',
    multiple: false,
    maxCount: 1,
    listType: 'picture-card',
    onChange(info) {
      const { status } = info.file;
      if (status === 'removed') remove_file();
    },
    beforeUpload: (file) => {
      console.log(file);
      const reader = new window.FileReader();
      reader.readAsDataURL(file);
      reader.onload = () => {
        var Base64Data = reader.result; // reader.result 就是转成base64的数据
        setImg(Base64Data);
      };
    },
    onPreview:(file)=>{
        console.log(file)
    }
  };

  return (
    <div>
      <Dragger {...upload_props}>
        <p className="ant-upload-drag-icon"></p>
        <p className="ant-upload-text">点击或拖入文件导入表格</p>
        <p className="ant-upload-hint">
          Support for a single or bulk upload. Strictly prohibit from uploading
          company data or other band files
        </p>
      </Dragger>
      <img src={img} alt="" />
    </div>
  );
};
